import request from '@/utils/request';
import type { Role } from '../entity';
import type {R} from '@/modules/common/entity';

const API_URL = '/manager/role';

export class RoleApi {
  // 获取所有角色
  async getAll(): Promise<R<Role[]>> {
    return request({
      url: API_URL,
      method: 'get'
    })
  }

  // 获取单个角色
  async getById(id: number): Promise<R<Role>> {
    return request({
      url: `${API_URL}/${id}`,
      method: 'get'
    })
  }

  // 创建新角色 
  async create(role: Role): Promise<R<Role>> {
    return request({
      url: API_URL,
      method: 'post',
      data: role
    })
  }  
  
  // 更新角色 
  async update(id: number, role: Role): Promise<R<Role>> {
    return request({
      url: API_URL+"/"+id,
      method: 'put',
      data: role
    })
  }  
  
  // 删除角色
  async delete(id: number): Promise<R<void>> {
    return request({
      url: API_URL+"/"+id,
      method: 'delete'
    })
  }
  // 获取角色对应的用户列表
  async getUsers(id: number): Promise<R<void>> {
    return request({
      url: API_URL+"/users",
      params:{id},
      method: 'get'
    })
  } 
}
